<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Desk;
use App\Models\Order;
use App\Models\Orderdetail;
use App\Models\Product;
use Illuminate\Http\Request;

class OrderdetailController extends Controller
{

    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request, Order $order)
    {
        $order->orderdetails()->create(
            [
                'amount' => $request->amount,
                'price' => $request->price,
                'order_id' => $order->id,
                'product_id' => $request->product_id,
            ]
        );
        return $this->message('修改成功');
    }

    /**
     * Display the specified resource.
     *
     * @param \App\Models\Orderdetail $orderdetail
     * @return \Illuminate\Http\Response
     */
    public function show(Orderdetail $orderdetail)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param \App\Models\Orderdetail $orderdetail
     * @return \Illuminate\Http\Response
     */
    public function edit(Orderdetail $orderdetail)
    {
        //
    }

    /**
     * 写入关联表order_product
     * @param Request $request
     * @param Order $order
     * @param Product $product
     */
    public function update(Request $request, Desk $desk, Order $order, Product $product)
    {
        Orderdetail::update(
            [
                'amount' => $request->amount,
                'price' => $request->price,
                'order_id' => $order->id,
                'product_id' => $product->id,
            ]
        );
        return $this->message('修改成功');
    }


    /**
     * Remove the specified resource from storage.
     *
     * @param \App\Models\Orderdetail $orderdetail
     * @return \Illuminate\Http\Response
     */
    public function destroy(Orderdetail $orderdetail)
    {
        //
    }
}
